package com.example.web.websystem.service;

import com.example.web.websystem.dao.SysRoleDao;
import com.example.web.websystem.dao.model.SysRoleDO;
import com.example.web.websystem.response.BusinessError;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by YangGang on 2021/1/26 9:25。
 */
@Service
public class SysRoleService {
    @Autowired
    private SysRoleDao sysRoleDao;


    @Transactional
    public int addSysRole(SysRoleDO sysRole) {
        sysRole.setRoleId(null);
        int i = sysRoleDao.insertSelective(sysRole);
        if (i != 1) throw new BusinessError("添加角色失败");
        return i;
    }

    @Transactional
    public int updateSysRole(SysRoleDO sysRole) {
        int up = sysRoleDao.updateByPrimaryKeySelective(sysRole);
        if (up != 1) throw new BusinessError("更新角色信息失败");
        return up;
    }

    /**
     * 查询-用户的角色列表
     *
     * @param userId
     * @return
     */
    public List<SysRoleDO> listSysRoleByUserId(long userId) {
        List<SysRoleDO> sysRoleDOList = sysRoleDao.listByUserId(userId);
        return sysRoleDOList;
    }


}
